# -*- coding:utf8 -*-
'''
Created on 2011-5-22

@author: Vendar
'''
from PyQt4 import QtCore,QtGui
from ui import LoginDlg_ui

class LoginDlg(QtGui.QDialog):
    def __init__(self,username="",parent=None):
        super(QtGui.QDialog,self).__init__(parent)
        
        #setup ui
        self.ui = LoginDlg_ui.Ui_LoginDlg()
        self.ui.setupUi(self)
        
        #init ui present
        self.ui.userNameEdit.setPlaceholderText('your email or account.')
        self.ui.passwdEdit.setPlaceholderText('enter your password.')
        self.ui.userNameEdit.setText(username)
        self.ui.passwdEdit.clear()
        self.ui.passwdEdit.setEchoMode(QtGui.QLineEdit.Password)
        self.ui.statusLabel.setText('please enter your account!!')
        self.ui.loginButton.setEnabled(False)
        
        #setup event connections
        self.ui.userNameEdit.textChanged.connect(self.OnAccountTextChanged)
        self.ui.passwdEdit.textChanged.connect(self.OnAccountTextChanged)
        self.ui.loginButton.clicked.connect(self.OnLogin)

    @QtCore.pyqtSlot(str)
    def OnAccountTextChanged(self,str):
        if len(self.ui.userNameEdit.text()) <= 0:
            self.ui.statusLabel.setText('please enter your account!!')
            self.ui.loginButton.setEnabled(False)
        elif len(self.ui.passwdEdit.text()) <= 0:
            self.ui.statusLabel.setText('please enter your password!!')
            self.ui.loginButton.setEnabled(False)
        else:
            self.ui.statusLabel.clear()
            self.ui.loginButton.setEnabled(True)
    
    @QtCore.pyqtSlot()
    def OnLogin(self):
        self.accept()
    
    def GetUserName(self):
        return self.ui.userNameEdit.text()
    
    def GetPassword(self):
        return self.ui.passwdEdit.text()